package testcase.app;

import java.io.IOException;

import javax.xml.parsers.ParserConfigurationException;

import org.json.JSONException;
import org.json.JSONObject;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.xml.sax.SAXException;

import api.app.Retry;
import common.Host;
import common.TestData;
/**
 * 帮忙医APP获取列表医生状态接口Retry测试用例
 * @author gaowen
 *
 */
public class TestRetry
{
	/**
	 * 帮忙医APP获取列表医生状态接口Retry测试环境数据驱动
	 * @return 测试数据
	 * @throws ParserConfigurationException
	 * @throws SAXException
	 * @throws IOException
	 */
	@DataProvider(name="Test")
	public static String[][] testRetryDataProvider() throws ParserConfigurationException, SAXException, IOException
	{
		Host.setup("Test");
		TestData tData=new TestData("app/TestRetry.xml");
		return tData.getParam();
	}
	
	/**
	 * 帮忙医APP获取列表医生状态接口Retry测试环境测试用例
	 * @param voipAccount 医生voip账号
	 * @param Type 类型
	 * @param token 调接口需要的token
	 * @throws IOException 
	 * @throws JSONException 
	 */
	@Test(dataProvider="Test",groups="Test")
	public void testRetryTestCase(String caseName,String voipAccounts,String rType,String token) throws IOException, JSONException
	{
		voipAccounts="["+voipAccounts+"]";
		//调用接口
		String result=Retry.get(voipAccounts, rType, token);
		
		JSONObject jsonResult;
		if (result==null||result.isEmpty())
		{
			jsonResult=null;
		}
		else
		{
			jsonResult=new JSONObject(result);
		}
		
		switch (caseName)
		{
			case "AndroidOne":
				Assert.assertTrue(jsonResult.getJSONObject("Data").getBoolean("Success"));
				break;
			case "AndroidTwo":
				Assert.assertTrue(jsonResult.getJSONObject("Data").getBoolean("Success"));
				break;
			case "AndroidZero":
				Assert.assertTrue(jsonResult.getJSONObject("Data").getBoolean("Success"));
				break;
			case "IOSOne":
				Assert.assertTrue(jsonResult.getJSONObject("Data").getBoolean("Success"));
				break;
			case "IOSTwo":
				Assert.assertTrue(jsonResult.getJSONObject("Data").getBoolean("Success"));
				break;
			case "IOSZero":
				Assert.assertTrue(jsonResult.getJSONObject("Data").getBoolean("Success"));
				break;
			case "VoipWrong":
				Assert.assertTrue(jsonResult.getJSONObject("Data").getBoolean("Success"));
				break;
			case "TypeWrong":
				Assert.assertTrue(jsonResult.getJSONObject("Data").getBoolean("Success"));
				break;
			case "TypeNull":
				Assert.assertTrue(jsonResult.getJSONObject("Data").getBoolean("Success"));
				break;
			case "TokenWrong":
				Assert.assertNull(result);
				break;
			case "TokenNull":
				Assert.assertNull(result);
				break;
			default:
				break;
		}
	}
}
